﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using CalcEngine;

namespace TestProject1
{
    /// <summary>
    /// Summary description for VariablesTest
    /// </summary>
    [TestClass]
    public class VariablesTest
    {
        public VariablesTest()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        Variables variables;

        [TestInitialize]
        public void Setup()
        {
            variables = new Variables();
        }

        [TestMethod]
        public void TestGetPI()
        {
            Assert.AreEqual(variables.PI, variables.Get("pi"));
            Assert.AreEqual(variables.PI, variables.Get("Pi"));
            Assert.AreEqual(variables.PI, Math.PI );
            Assert.AreEqual(Math.PI, variables.Get("Pi"));
        }

        [TestMethod]
        public void TestGetExp()
        {
            Assert.AreEqual(variables.EXP, variables.Get("e"));
            Assert.AreEqual(variables.EXP, variables.Get("E"));
            Assert.AreEqual(variables.EXP,Math.Exp(1));
            Assert.AreEqual(Math.Exp(1), variables.Get("e"));
        }
        [TestMethod]
        public void TestSetExpOrPI()
        {

            try
            {
                variables.Set("PI", 1);
                Assert.Fail("Argument exception should be thrown if PI is set");
            }
            catch (ArgumentException)
            {

            }
            catch
            {
                Assert.Fail("Argument exception should be thrown if PI is set");
            }
            try
            {
                variables.Set("E", 1);
                Assert.Fail("Argument exception should be thrown if E is set");
            }
            catch (ArgumentException)
            {

            }
            catch
            {
                Assert.Fail("Argument exception should be thrown if PI is set");
            }
        }

        [TestMethod]
        public void TestSetValues()
        {
            variables.Set("ax", 1.0);
            Assert.AreEqual(1.0, variables.Get("ax"));
            variables.Set("bx", 1);
            Assert.AreEqual(1, variables.Get("ax"));
            variables.Set("ax", 5);
            Assert.AreEqual(5, variables.Get("ax"));
        }
    }
}
